import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
import java.util.Iterator;

/**
 * Write a description of class Jugador here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Jugador extends Elemento
{
 
    private int dir;
    private int x;
    private int y;
    private Vidas v;
    
    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public Jugador()
    
    {

        x=300;
        y=50;
        dir=1;
    }

    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public void iniciaVidas()
    {
        List list=getWorld().getObjects(Vidas.class);
        Iterator it=list.listIterator();
        while(it.hasNext()){
         Vidas i=(Vidas)it.next();
         v=i;
        }
    }


    
    /**
     * Act - do whatever the Jugador wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        mueve();
        checaPicos();
    }  
    
    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public boolean mueve()
    {
       Obstaculo ob=(Obstaculo)getOneIntersectingObject(Obstaculo.class);
       
       if(ob==null)
       {
        setLocation((int)x,(int)y++);
       }
       else{
        ob.desliza(this);
        setLocation((int)x,(int)y);
        }
         
       return true;
    }
    
    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public void cambiaX(int a)
    {
        x=x+a;
    }
    
    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public int dameDireccion()
    {
     getImage().drawString(""+dir+"",20,8);
     return dir;
    }
    
    
    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public void cambiaDireccion(int  d)
    {
        
        getImage().drawString(""+d+"",10,8);
        dir=d;
        
    }   
    
    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public Vidas dameVidas()
    {
        // put your code here
        return v;
    }

    /**
     * An example of a method - replace this comment with your own
     *
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y
     */
    public void checaPicos()
    {  
       Picos p=(Picos)getOneIntersectingObject(Picos.class);
       if(p!=null)
       {
          this.dameVidas().cambiaVidas();
          x=300;
          y=50;
          setLocation(x,y);
       }

    }


    
    
}
